package com.itheima.leetcode.od.a.bitmap;

/**
 * <h3>BitMap</h3>
 */
public class BitMap {
    // 数据容器
    private byte[] byteBits;
    // 最大值
    private int maxValue;
    // 容量
    private int capacity;

    public BitMap(int maxValue) {
        this.maxValue = maxValue;
        this.capacity = maxValue / 8 + 1;
        this.byteBits = new byte[capacity];
    }

    private void add(int num) {
        int index = num / 8;
        int position = num % 8;
        int tempBit = 1 << position;
        byteBits[index] = (byte) (byteBits[index] | tempBit);
    }

    private boolean contain(int num) {
        int index = num / 8;
        int position = num % 8;
        int tempBit = 1 << position;
        return (byteBits[index] & tempBit) != 0;
    }
}
